package com.example.controller;
import com.example.entity.Goodstype;
import com.example.service.GoodstypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin")
public class Goodstypecontroller {
@Resource
    GoodstypeService goodstypeService;

@RequestMapping(value = "/goodstype",method = {RequestMethod.GET,RequestMethod.POST})
public String findAllGoodStype(Model model, HttpServletRequest request,
    @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum
,@RequestParam(value = "pageSize",required = false,defaultValue = "4")Integer pageSize){
        PageInfo<Goodstype> goodstypelist = goodstypeService.queryAll(pageNum,pageSize);
        model.addAttribute("goodstypelist",goodstypelist);
        return "goodstypeList";
    }
    @GetMapping("/delGoodstype/{id}")
    public String delGoodstype(@PathVariable("id")int id, Model model){
    int num =goodstypeService.deleteByID(id);
    model.addAttribute("msg","删除成功");
    return "forward:/admin/goodstype";
    }
    @GetMapping("/goodstype/{id}")
    public String getGoodstypeById(@PathVariable("id") int id, Model model){
    Goodstype goodstype =goodstypeService.findById(id);
    model.addAttribute("goodstype",goodstype);
    return "editGoodstype";
    }

    @PostMapping("/editGoodstype")
    public String addGoodstype(Goodstype goodstype,Model model){
        System.out.println(goodstype);
        int num = goodstypeService.update(goodstype);
        model.addAttribute("msg","商品种类更新成功");
    return "editGoodstype";
    }

    @GetMapping("/goodstypeadd")
    public String insertGoodstype(Goodstype goodstype,Model model){
    return "goodstypeadd";
    }

    @PostMapping("/goodstype2")
    public String addGoodstype2(Goodstype goodstype,Model model){
        System.out.println(goodstype);
        int num2 = goodstypeService.insert(goodstype);
        return "redirect:/admin/goodstype";
    }



}
